/*
 * @Author: wuqingchun
 * @Date: 2024-10-29 19:33:44
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-10-31 20:56:27
 */
#ifndef __NET_TCP_LISTENER_H__
#define __NET_TCP_LISTENER_H__

#include <unordered_set>
#include <netinet/in.h>

#include "libnet.h"
#include "net_event_handler.h"

class CNetConnectionListener : public INetTCPConnection
{
public:
    CNetConnectionListener(INetEventHandler& refEventHandler, INetTCPConnectionCallback& refCallback, const sockaddr_in& refAddr);

    ~CNetConnectionListener();

    int32_t Init();

    void Exit();

    void DeleteConnection(INetTCPConnection* pobjConnection);
public:
    virtual int GetFd() override final;
    virtual int32_t DealRDEvent() override final;
    virtual int32_t DealWREvent() override final;
    virtual int32_t DealERREvent() override final;
    virtual int32_t Send(const void* pData, size_t ulDataLen) override final;
    virtual void Close() override final;
private:
    INetEventHandler& m_refEventHandler;
    INetTCPConnectionCallback& m_refCallback;
    sockaddr_in m_stAddr;
    int m_iSockFd = -1;
    std::unordered_set<INetTCPConnection*> m_setPassiveConn;
};

#endif //__NET_TCP_LISTENER_H__